package com.stellar.circle.basic.service.impl;

import com.stellar.circle.basic.dao.SSchoolDao;
import com.stellar.circle.basic.entity.SSchool;
import com.stellar.circle.basic.service.SSchoolService;
import com.stellar.web.core.enums.IsDeletedFlagEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 学校信息表(SSchool)服务实现
 *
 * @author Jqchan
 * @since 2025-05-17 18:48:37
 */
@Service
public class SSchoolServiceImpl implements SSchoolService {

    @Resource
    private SSchoolDao sSchoolDao;

    @Override
    public SSchool queryById(Long id) {
        return sSchoolDao.queryById(id);
    }

    @Override
    public SSchool queryByCondition(SSchool condition) {
        return sSchoolDao.queryByCondition(condition);
    }

    @Override
    public List<SSchool> queryAllByCondition(SSchool condition) {
        return sSchoolDao.queryAllByCondition(condition);
    }

    @Override
    public List<SSchool> page(SSchool condition, int page, int pageSize) {
        return sSchoolDao.page(condition, page, pageSize);
    }

    @Override
    public int insert(SSchool entity) {
        return sSchoolDao.insert(entity);
    }

    @Override
    public int update(SSchool entity) {
        return sSchoolDao.update(entity);
    }

    @Override
    public int deleteById(Long id) {
        return sSchoolDao.deleteById(id);
    }

    @Override
    public Long count(SSchool condition) {
        return sSchoolDao.count(condition);
    }

    @Override
    public List<SSchool> getSchoolListByLocation(Double longitude, Double latitude) {
        return sSchoolDao.getSchoolListByLocation(longitude, latitude);
    }

    @Override
    public List<SSchool> batchQueryByIds(List<Long> schoolIds) {
        return sSchoolDao.batchQueryByIds(schoolIds);
    }

    @Override
    public Map<Long, String> batchQuerySchoolNames(List<Long> schoolIds) {
        if (schoolIds == null || schoolIds.isEmpty()) {
            return Collections.emptyMap();
        }

        List<SSchool> schools = sSchoolDao.batchSelectByIds(schoolIds);

        return schools.stream()
                .filter(s -> s.getIsDeleted() == IsDeletedFlagEnum.UN_DELETED.getVal())
                .collect(Collectors.toMap(
                        SSchool::getId,
                        SSchool::getSchoolName,
                        (existing, replacement) -> existing
                ));
    }
}
